﻿//using System;
//using System.Collections.Generic;
//using System.Collections.Specialized;
//using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Audio;
//using Microsoft.Xna.Framework.Content;
//using Microsoft.Xna.Framework.GamerServices;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
//using Microsoft.Xna.Framework.Net;
//using Microsoft.Xna.Framework.Storage;
//using FarseerGames.FarseerPhysics.Dynamics;
//using FarseerGames.FarseerPhysics.Collisions;
//using FarseerGames.FarseerPhysics.Controllers;
//using FarseerGames.FarseerPhysics.Factories;
//using System.Text;
//using PhysicsObjects;

//using FarseerGames.FarseerPhysics;
//using UnitLibrary.GameObjects;
//using UnitLibrary.Utility;
//using UnitLibrary.GameObjects.Units;


//namespace UnitLibrary.Managers
//{
//    public enum TowerAIType
//    {
//    }
//    public enum PlayerAIType
//    {
//    }
//    public class AIM : Manager
//    {
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="game"></param>
//        /// <param name="numWaypoints"></param>
//        public AIM(Game game, ComponentM mainGameScreen, int numWaypoints, int numSpawnPoints, double maxTime)
//            : base(game, mainGameScreen)
//        {
//            _numSpawnpoints = numSpawnPoints;
//            _numWaypoints = numWaypoints;
//            _maxTime = 500;
//            _waypoints = new Vector2[_numWaypoints];
//            _spawnpoints = new Vector2[_numSpawnpoints];
            
//        }

//        public static string UnitName = "Default";

//        /// <summary>
//        /// 
//        /// </summary>
//        private double _timer = 0;

//        /// <summary>
//        /// 
//        /// </summary>
//        private double _maxTime = 500;

//        /// <summary>
//        /// 
//        /// </summary>
//        private int _counter = 0;

//        private int _unitsAtThisSpawnPoint = 0;

//        private int _maxUnitsAtSpawnPoint = 10;

//        private int _maxEnemies = 100;

//        private bool _initializerFlag = true;

//        private Random random = new Random();

//        /// <summary>
//        /// 
//        /// </summary>
       

//        /// <summary>
//        /// Update the enemy AI. This class will directly manipulate the enemy objects as need be in order for game to play right.
//        /// </summary>
//        /// <param name="gameTime"></param>
//        public void Update(GameTime gameTime)
//        {
//            _timer += gameTime.ElapsedGameTime.TotalMilliseconds;
//            //if (_timer > _maxTime && _initializerFlag == true)
//            //{
//            //    if (_components.enemyManager.UnitPool.ActiveCount < _maxEnemies)
//            //    {
//            //        _components.CreateUnit(UnitID.Enemy, UnitName, _spawnpoints[_counter], Vector2.Zero);
//            //        _unitsAtThisSpawnPoint++;
//            //        if (_unitsAtThisSpawnPoint > _maxUnitsAtSpawnPoint)
//            //        {
//            //            _counter = Util.random.Next(0, _numSpawnpoints);
//            //        }
//            //        _timer = 0;

//            //    }
//            //    _initializerFlag = false;
//            //}
//            //else 
//            if (_timer > _maxTime)
//            {
//                //_updateAI();
//                //_enemyMovementAI();
//                _components.CreateUnit(UnitID.Enemy, UnitName, new Vector2(1000, 1000), Vector2.Zero);
//                _timer = 0;
//                //_initializerFlag = true;
//            }
//        }

//        /// <summary>
//        /// The main function for enemy AI units to call
//        /// In this function, the enemy AI will call this function, given their current position and AI Type.
//        /// The function will return the coordinate where they need to head to next.
//        /// </summary>
//        /// <param name="currentPosition"></param>
//        /// <param name="AIType"></param>
//        /// <returns></returns>
//        public Vector2 Update(Vector2 currentPosition, AIType AIType)
//        {
//            Vector2 tempVector = Vector2.Zero;
//            if (AIType == AIType.Player)
//                return _components.UnitPosition(UnitID.Player, 0);
//            if (AIType == AIType.Waypoint)
//                return GetWaypoint(currentPosition);
//            else return tempVector;
//        }

//        #region AI code
//        private Random _randomPOS = new Random();
//        //function to spawn enemy ai
//        public void _updateAI()
//        {
//            //20% of the time the enemies will spawn right near the player during the next update path
//            //this makes the user not be able to stay in one position and win the game
//            //forces the user to move
//            if (_randomPOS.Next(0, 100) < 10)
//            {
//                do
//                {
//                    _tempVector2.X = _randomPOS.Next(-100, 100);
//                    _tempVector2.Y = _randomPOS.Next(-100, 100);
//                } while (_tempVector2.X >= -40 && _tempVector2.X <= 40 &&
//                    _tempVector2.Y >= -40 && _tempVector2.Y <= 40);

//                _tempVector2_.X = _components.UnitPosition(UnitID.Player, 0).X + _tempVector2.X;
//                _tempVector2_.Y = _components.UnitPosition(UnitID.Player, 0).Y + _tempVector2.Y;

//                _components.CreateUnit(UnitID.Enemy, UnitName, _tempVector2_, Vector2.Zero);
//                _unitsAtThisSpawnPoint++;
//                if (_unitsAtThisSpawnPoint > _maxUnitsAtSpawnPoint)
//                    _counter = random.Next(0, _numSpawnpoints);
//                _timer = 0;

//            }
//            //will spawn enemies near the player after the initial spawns
//            else
//            {
//                do
//                {
//                    _tempVector2.X = _randomPOS.Next(-500, 500);
//                    _tempVector2.Y = _randomPOS.Next(-500, 500);
//                } while (_tempVector2.X >= -100 && _tempVector2.X <= 100 &&
//                       _tempVector2.Y >= -100 && _tempVector2.Y <= 100);
//                _tempVector2_.X = _components.UnitPosition(UnitID.Player, 0).X + _tempVector2.X;
//                _tempVector2_.Y = _components.UnitPosition(UnitID.Player, 0).Y + _tempVector2.Y;

//                _components.CreateUnit(UnitID.Enemy, UnitName, _tempVector2_, Vector2.Zero);
//                _unitsAtThisSpawnPoint++;
//                if (_unitsAtThisSpawnPoint > _maxUnitsAtSpawnPoint)
//                    _counter = random.Next(0, _numSpawnpoints);
//                _timer = 0;
//            }
//        }
//        #endregion

//        #region AI Logic Test

//        public void _enemyMovementAI()
//        {
//            _tempVector2_.X = 100;
//            _tempVector2_.Y = 100;

//            if (_unitsAtThisSpawnPoint < 10)
//            {
//                //_components.CreateUnit(UnitID.Enemy, UnitName, _tempVector2_, Vector2.Zero);
//                _unitsAtThisSpawnPoint++;
//            }

//        }
//        #endregion

//        #region SpawnPoint Logic

//        private int _numSpawnpoints;

//        /// <summary>
//        /// 
//        /// </summary>
//        private Vector2[] _spawnpoints;

//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="spawnpoint"></param>
//        /// <returns></returns>
//        public Vector2 GetSpawnpoint(int spawnpoint)
//        {
//            if (spawnpoint > _numSpawnpoints)
//                throw new Exception("Out of range");
//            return _spawnpoints[spawnpoint];
//        }

//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="currentpoint"></param>
//        /// <returns></returns>
//        public Vector2 GetSpawnpoint(Vector2 currentpoint)
//        {
//            float currentdistance = 0f;
//            float previousdistance = 1000f;
//            int closestindex = 0;
//            for (int i = 0; i < _numWaypoints; i++)
//            {
//                currentdistance = Vector2.Distance(currentpoint, _waypoints[i]);
//                if (currentdistance < previousdistance)
//                    closestindex = i;
//                previousdistance = currentdistance;
//                if (currentdistance < 300f)
//                {
//                    return _spawnpoints[i];
//                }
//            }
//            return _spawnpoints[closestindex];
//        }

//        private void ReassignSpawnPoints()
//        {
//            //todo: create better function that will create spawn points along the edges of the screen
//            for (int i = 0; i < _numSpawnpoints; i++)
//            {
//                _spawnpoints[i].X = random.Next(100, (int)_components.mapManager.WorldWidth);
//                _spawnpoints[i].Y = random.Next(100, (int)_components.mapManager.WorldHeight);
//            }
//        }
//        #endregion

//        #region WayPointLogic

//        /// <summary>
//        /// Current number of waypoints
//        /// </summary>
//        private int _numWaypoints;

//        /// <summary>
//        /// Array holding all the waypoints in the game
//        /// </summary>
//        private Vector2[] _waypoints;

//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="waypoint">Number of the waypoint on the container</param>
//        /// <returns>waypoint given the specified number</returns>
//        public Vector2 GetWaypoint(int waypoint)
//        {
//            if (waypoint > _numWaypoints)
//                throw new Exception("Out of range");
//            return _waypoints[waypoint];
//        }

//        /// <summary>
//        /// Finds the closest position to this waypoint
//        /// </summary>
//        /// <param name="currentPosition"></param>
//        /// <returns></returns>
//        public Vector2 GetWaypoint(Vector2 currentpoint)
//        {
//            float currentdistance = 0f;
//            float previousdistance = 1000f;
//            int closestindex = 0;
//            for (int i = 0; i < _numWaypoints; i++)
//            {
//                currentdistance = Vector2.Distance(currentpoint, _waypoints[i]);
//                if (currentdistance < previousdistance)
//                    closestindex = i;
//                previousdistance = currentdistance;
//                if (currentdistance < 300f)
//                {
//                    return _waypoints[i];
//                }
//            }
//            return _waypoints[closestindex];
//        }

//        /// <summary>
//        /// 
//        /// </summary>
//        /// 
//        private void ReassignWayPoints()
//        {


//            /*/ moving enemys in a line patrolling
//            for (int i = 0; i < _numWaypoints; i++)
//            {
//                _waypoints[0].X = 200 * i;
//                _waypoints[0].Y = 200 * i;
//            }*/

//            //original waypoint idea
//            for (int i = 0; i < _numWaypoints; i++)
//            {
//                _waypoints[i].X = random.Next(100, (int)_components.mapManager.WorldWidth);
//                _waypoints[i].Y = random.Next(100, (int)_components.mapManager.WorldHeight);
//            }
//        }



//        #endregion

//        #region HuntTower
//        #endregion

//        #region HuntPlayerLogic

//        #endregion

//        #region HuntTowerLogic

//        //public Vector2 GetTower(Vector2 currentlocation)
//        //{
//        //    Vector2 position;
//        //    int nodeindex;
//        //    int closestindex = 0;
//        //    float currentdistance = 0;
//        //    float previousdistance = 0;
//        //    //foreach(RPool<GameUnit<Tower, PhyObj>>.Node tower in _components.towerManager.TowerPool.ActiveNodes)
//        //    //{
//        //    //    nodeindex = tower.NodeID;
//        //    //    currentdistance = Vector2.Distance(currentlocation, _components.towerManager.TowerPool.Get(nodeindex).Item.PType.Position);
//        //    //    if (currentdistance > previousdistance)
//        //    //        closestindex = nodeindex;
//        //    //}
//        //    // return _components.towerManager.TowerPool.Get(closestindex).Item.PType.Position;
//        //    //}
//        //}
//        #endregion

//        #region SurvivorLogic
//        #endregion

//        #region HuntPOCLogic
//        #endregion
//    }
//}

